<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>首页</title>
    <meta charset="utf-8">
    <%@ include file="/WEB-INF/pages/common/common.jsp" %>
    <style>
        li {
            list-style: none;
            font-size: 14px;
            margin: 2px;
        }
    </style>
</head>
<body class="easyui-layout">
<div data-options="region:'north',split:true" style="height:100px;">
    <div style="float: right">
        <p id="personName"><p>
        <p><a href="${pageContext.request.contextPath}/admin/logout">退出</a></p>
    </div>
</div>
<div data-options="region:'south',split:true" style="height:100px;"></div>
<div data-options="region:'west',split:true" style="width:280px;">
    <div id="menu" style="padding-left: 20px;font-size: 16px;">

    </div>
</div>
<div data-options="region:'center'" style="padding:5px;">
    <div id="center" class="easyui-tabs" fit="true" border="false">
        <div id="home" title="home" style="height: 100%; width: 100%;">
            公仔SDK管理后台
        </div>
    </div>
</div>
</body>
<script type="application/javascript">

    window.onload = function () {
        personInfo();
        initAccordion();
    }

    function addTab(title, url) {
        if ($('#center').tabs('exists', title)) {
            $('#center').tabs('select', title);
        } else {
            var content = '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>';
            $('#center').tabs('add', {
                title: title,
                content: content,
                closable: true
            });
        }
    }

    function initAccordion() {
        $.ajax({
            type: "GET",
            async: false,
            cache: false,
            dataType: "json",
            url: "${pageContext.request.contextPath}/admin/purview/queryMenu",
            success: function (resp) {
                if(resp.code==0){
                    var menuArr = resp.data;
                    buildMenu('#menu',menuArr)
                    $('#menu').panel({
                        title:'导航菜单',
                        collapsible:true,
                        minimizable:false,
                        maximizable:false,
                        closable:false,
                        fit:true
                    });
                }else{
                    $.messager.alert('Warning','执行出错了,state:'+resp.msg);
                }
            },
            error:function(err){
                console.log(err);
            },

        });

    }

    function buildMenu(root, menuArr) {
        for(var i=0;i<menuArr.length;i++){
            var menu = menuArr[i];
            if(menu.children.length>0){
                $(root).append('<div id="'+menu.id+'" class="easyui-panel" title="'+menu.text+'" style="padding-left: 20px;border-right: none;border-left: none;border-bottom: none;" data-options="collapsible:true,minimizable:false,maximizable:false,closable:false,fit:true,collapsed:true"></div>')
                buildMenu('#'+menu.id,menu.children)
                $('#'+menu.id).panel({
                    title:menu.text,
                    collapsible:true,
                    minimizable:false,
                    maximizable:false,
                    closable:false
                });
            }else{
                if(menu.type==2){
                    $(root).append('<ul><li><a href="#" onclick="addTab(\''+menu.text+'\',\'${pageContext.request.contextPath}'+menu.target+'\')">'+menu.text+'</a></li></ul>')
                }else{
                    $(root).append('<ul><li><a href="#" onclick="addTab(\''+menu.text+'\',\''+menu.target+'\')">'+menu.text+'</a></li></ul>')
                }

            }

        }
    }

    function personInfo() {
        $.ajax({
            type: "GET",
            async: false,
            cache: false,
            dataType: "json",
            url: "${pageContext.request.contextPath}/admin/person/info",
            success: function (resp) {
                if(resp.code==0){
                    $('#personName').append(resp.data.name);
                }else{
                    $.messager.alert('Warning','执行出错了,state:'+resp.msg);
                }
            },
            error:function(err){
                console.log(err);
            },

        });
    }
</script>

</html>
